/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BusyBox.java
 *
 * Created on Oct 23, 2009, 10:17:36 AM
 */

package org.workplicity.marist.grounds.ui;

import java.awt.Frame;


/**
 *
 * @author Ron
 */
public class BusyBox extends javax.swing.JDialog implements Runnable {
    private Frame parent;

    /** Creates new form BusyBox */
    public BusyBox(java.awt.Frame parent) {
        super(parent, true);

        this.parent = parent;

        initComponents();
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        msgLabel = new javax.swing.JLabel();
        cancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        msgLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        msgLabel.setText("Working, please standby...");

        cancelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/remove.png"))); // NOI18N
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(msgLabel)
                .addContainerGap(44, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(176, Short.MAX_VALUE)
                .addComponent(cancelButton)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(msgLabel)
                .addGap(18, 18, 18)
                .addComponent(cancelButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_cancelButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                BusyBox dialog = new BusyBox(new javax.swing.JFrame());
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel msgLabel;
    // End of variables declaration//GEN-END:variables

    public void run() {
        this.setVisible(true);
    }

    public void done() {
        this.dispose();
    }

    public void showMessage(String msg) {
        this.msgLabel.setText(msg);

        this.setLocationRelativeTo(parent);

        setVisible(true);

        Thread thread = new Thread(this);
        thread.start();
    }

    public void showMessage() {
        showMessage("Working, please standby...");
    }

}
